package fr.blogger.web.bean.module;

import java.io.Serializable;

import javax.annotation.PostConstruct;
import javax.faces.view.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;

import fr.blogger.ejb.facade.BlogFacade;
import fr.blogger.ejb.model.Blog;
import fr.blogger.ejb.outils.UtilsAuthentication;
import fr.blogger.web.outils.UtilsJsf;

@Named
@ViewScoped
public class DetaillerBlogBean implements Serializable {

	@Inject
	private BlogFacade blogFacade;
	private Blog blog;

	public DetaillerBlogBean() {
	}

	@PostConstruct
	private void initialisation() {
		String id = UtilsJsf.getRequestParameter("blogId");
		blog = blogFacade.find(Integer.valueOf(id));
	}
	
	public void abonnement() {
		 blogFacade.abonner(UtilsAuthentication.getUserSession(), blog);
		 UtilsJsf.ajoutMessageInfo("Vous êtes maintenant abonné à ce blog");
	}
	
	public void desabonnement() {
		 blogFacade.desabonner(UtilsAuthentication.getUserSession(), blog);
		 UtilsJsf.ajoutMessageInfo("Vous êtes maintenant désabonné à ce blog");
	}

	public Blog getBlog() {
		return blog;
	}

	public void setBlog(Blog blog) {
		this.blog = blog;
	}

}
